#ifndef NET_H
#define NET_H
#ifndef NO_GRAPHIC
#include <SDL2/SDL_net.h>
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#endif
#include "cell.h"
#include "defines.h"

struct Package {
    struct Cell cell;
    int x, y;
    enum pkgType type;
};

struct Net {
#ifndef NO_GRAPHIC
    TCPsocket client;
    IPaddress remoteIp;
#else
    int client;
    struct sockaddr_in remoteIp;
#endif
    struct Package pkgList[MAX_PKG_COUNT];
    int pkgCount;
    bool active;
};

#ifndef NO_GRAPHIC
#define returnType int
#else
#define returnType void*
#endif

struct Net* N_init(char* addres, int port);
void N_send(struct Net *n, struct Package pkg);
struct Package N_get(struct Net *n);
void N_close(struct Net *n);
returnType N_readServerMessages(void *n_void);
void N_popPkg(struct Net *n, struct Package *pkg);

#endif
